import requests
from lxml import etree
import os
import shutil
if os.path.exists('static/折纸'):
    shutil.rmtree('static/折纸')
os.mkdir('static/折纸')

url = 'https://www.aizhezhi.com/list/zhezhi/1.html'

res = requests.get(url)
# print(res.status_code)

# print(res.content.decode('utf-8'))
datas = res.content.decode('utf-8')
html_info = etree.HTML(datas)
titles = html_info.xpath('//div[@class="contentlist"]/article[@class="excerpt list5"]//a/@title')
links = html_info.xpath('//div[@class="contentlist"]/article[@class="excerpt list5"]//a/@href')
image_url = html_info.xpath('//article[@class="excerpt list5"]/p[@class="image-container"]/a[@class="focus"]/img[@class="thumb"]/@src')
for title, link, image in zip(titles, links, image_url):
    total_link = 'https://www.aizhezhi.com' + link
    total_image_url = 'https://www.aizhezhi.com' + image
    image_data = requests.get(total_image_url)
    with open(f'static/折纸/{title}.jpg', 'wb') as f:
        f.write(image_data.content)
    print({'title': title, 'link': total_link, 'image': total_image_url})

